/* ******************************************************************
 * This file is part of the escal project and distributed under the
 * terms of the GNU General Public License Version 3
 * Copyright (C) 2008 Epocher (xijiaosdq@gmail.com)
 * See COPYING file for licensing information.
 *******************************************************************/

#ifndef ESCAL_GUI_H
#define ESCAL_GUI_H

#include "ui_escal_gui.h"
#include "url_dialog.h"
#include "task_view.h"
#include "folder_list_model.h"
#include "task_model.h"
#include "task.h"
#include <QtGui>

class QSystemTrayIcon;
class QClipboard;
class PreferenceDialog;
class ScannerDialog;
class TaskViewDelegate;
class TaskInfoWidget;

class EscalGui:public QMainWindow, protected Ui::EscalGui
{
	Q_OBJECT
public:
	EscalGui(QWidget* parent=0);
	~EscalGui();
public slots:
	bool 	close();
	void	saveData();
	void 	about();
	void 	aboutQt();
	/*
	 * get the input from user or clipboard (no done)
	 * and create a new task . 
	 */
	void newTask(const QString &urlStr=QString());
	/*
	 * get the selections from unDoneTaskView
	 * and start the corresponding tasks
	 */
	void startSelected();
	/*
	 * get the selections from unDoneTaskView
	 * and pause the corresponding tasks
	 */
	void pauseSelected();
	/*
	 * get the selections from unDoneTaskView
	 * and stop the corresponding tasks
	 */
	void stopSelected();
	void increaseSelected();
	void cutDownSelected();
	/*
	 * get the selections from unDoneTaskView
	 * and cancel the corresponding tasks
	 */
	void cancelSelected();
	void deleteDataSelected();
	void deleteSelectedFolder();
	void moveUpSelectedFolder();
	void moveDownSelectedFolder();
	void moveToTopSelectedFolder();
	void moveToBottomSelectedFolder();
	/*
	 * show the preference window
	 */
	void preference();
	void restoreOrMinimize();
	void taskCompleted(BaseTask *task);
	void taskDeleted(BaseTask *task);
	void clipboardDataChanged();
	void undoneTaskClicked(const QModelIndex & index=QModelIndex());
	void doneTaskClicked(const QModelIndex & index=QModelIndex());
	void folderClicked(const QModelIndex & index=QModelIndex());
	void contextMenuEvent ( QContextMenuEvent * event );
	void getPassedUrl(const QString &urlStr);
	void trayActivated(QSystemTrayIcon::ActivationReason reason );
	void htmlScanner();
	void addTask(QUrl url, QString folderName, QString fileName,
			int threadNum);
protected slots:
	void closeEvent ( QCloseEvent * event );
private:
	/*
	 * connect the actions' singal with the slots 
	 */
	void buildViews();
	void buildModels();
	void buildContextMenus();
	QSplitter *splitter1;
	QSplitter *splitter2;
	QWidget *infoWindow;
	TaskInfoWidget *taskInfoWidget;
	UndoneTaskView *undoneTaskView;
	DoneTaskView *doneTaskView;
	QTreeView *folderView;
	QTreeView *dirView;
	UndoneTaskModel *undoneTaskModel;
	DoneTaskModel *doneTaskModel;
	FolderListModel *folderListModel;
	QDirModel *dirModel;
	UndoneTaskViewDelegate *undoneTaskViewDelegate;
	QAction *resOrMin;
	QMenu *undoneTaskMenu;
	QMenu *doneTaskMenu;
	QMenu *infoMenu;
	QMenu *trayMenu;
	QSystemTrayIcon *trayIcon;
	QClipboard *clipboard;
	UrlDialog *urlDialog;
	ScannerDialog *scannerDialog;
	PreferenceDialog *preferenceDialog;
};


#endif /* ESCAL_GUI_H */
